def find_perfect_numbers(N):
    perfect_numbers = []

    for num in range(1, N + 1):
        # 找出所有因子（不包括它本身）
        # 主要是找出因子
        factors = [i for i in range(1, num) if num % i == 0]
        # 计算因子之和
        sum_of_factors = sum(factors)

        # 如果因子之和等于原数，则为完数
        if sum_of_factors == num:
            perfect_numbers.append((num, factors))

    return perfect_numbers

# 示例：找出1000以内的所有完数
N = 1000
perfect_numbers_up_to_N = find_perfect_numbers(N)
print(perfect_numbers_up_to_N)
